package displayboardinfo.tests;

import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

import displayboardinfo.entities.User;
import displayboardinfo.utils.Utils;

public class LoginTest {
	public static void main(String[] args) {
		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		WebResource service = client.resource(getBaseURI());
		
		User user = new User();
		user.setLogin("rejestracja");
		user.setPassword(Utils.convertToSHA1("password"));
		
		try{
			ClientResponse res = service.path("login").type(MediaType.APPLICATION_XML).post(ClientResponse.class, user);
			
			if (res.getStatus() == ClientResponse.Status.NOT_ACCEPTABLE.getStatusCode()){
				System.err.println("Not acceptable");
				System.err.println(res.getEntity(String.class));
			}
			else {
				System.out.println(res);
				User userRes = res.getEntity(User.class);
				System.out.println(userRes);
			}
			
			
			
			
			
			
		} catch (Exception e){
			System.err.println("Exception");
		}
		
	}
	
	private static URI getBaseURI() {
		return UriBuilder.fromUri(
				"http://localhost:8080/DisplayBoardInfoServer").build();
	}
}
